package com.cetc39.service.impl;

import java.util.List;
import java.util.Map;

import com.cetc39.bean.Role;
import com.cetc39.bean.User;
import com.cetc39.dao.UserDao;
import com.cetc39.service.UserService;
import com.opensymphony.xwork2.ActionContext;

public class UserServiceImpl implements UserService {

	private UserDao userDao;
	
	@Override
	public void add(User user) {
		userDao.save(user);
	}

	@Override
	public String findByUserid(String userid, String password) {
		List<?> list = userDao.findByUserid(userid, password);
		if(list.size() > 0) {
			Map<String, Object> session = ActionContext.getContext().getSession();
			session.put("user", list.get(0));
			return "success";
		}
		return "fail";
	}

	@Override
	public void delete(int id) {
		userDao.delete(id);
	}

	@Override
	public void updata(User user) {
		userDao.updata(user);
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public List<?> findAll() {
		
		return userDao.findAll();
	}

	@Override
	public List<?> findByRole(Role r) {
		
		return userDao.findUserByRole(r);
	}

	@Override
	public User findById(int id) {
		
		return userDao.findById(id);
	}

	
}
